package com.five.matebook.activity;

import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.five.matebook.R;
import com.five.matebook.activity.db.OneQueryData;
import com.five.matebook.activity.income.IncomeLsitFragment;

import java.util.List;

public class InrecordViewDialog extends DialogFragment {
    List<OneQueryData> mData = null;
    IncomeLsitFragment fragment;
    public InrecordViewDialog(List<OneQueryData> data) {
        this.mData = data;
        fragment = new IncomeLsitFragment(data);
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return inflater.inflate(R.layout.dialog_outcome_view, null);
    }

    private volatile boolean mFirstStart = true;
    @Override
    public void onStart() {
        super.onStart();
        if (mFirstStart) {
            // 获取屏幕宽度和高度
            WindowManager.LayoutParams layoutParams = getDialog().getWindow().getAttributes();
            DisplayMetrics displayMetrics = getContext().getResources().getDisplayMetrics();
            int screenWidth = displayMetrics.widthPixels;
            int screenHeight = displayMetrics.heightPixels;

            // 设置对话框宽度和高度为屏幕宽度和高度的
            int dialogWidth = (int) (screenWidth * 0.95);
            int dialogHeight = (int) (screenHeight * 0.7);
            layoutParams.width = dialogWidth;
            layoutParams.height = dialogHeight;
            getDialog().getWindow().setAttributes(layoutParams);

            // 设置圆角
            getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            getDialog().getWindow().setBackgroundDrawableResource(R.drawable.outrecord_dialog_bg);

            FragmentTransaction fragmentTransaction = getChildFragmentManager().beginTransaction();;
            fragmentTransaction.add(R.id.fragment_container_view, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
        mFirstStart = false;
    }

    @Override
    public void show(@NonNull FragmentManager manager, @Nullable String tag) {
        super.show(manager, tag);
    }
}
